package com.easy;

/**
 * Created by Lxk on 2020/1/24.
 */
public class Solution111 {

    private int getMinDepth(TreeNode node) {
        if (node.left == null && node.right == null) {
            return 1;
        }
        int left = Integer.MAX_VALUE;
        if (node.left != null) {
            left = getMinDepth(node.left);
        }
        int right = Integer.MAX_VALUE;
        if (node.right != null) {
            right = getMinDepth(node.right);
        }
        return left < right ? left + 1 : right + 1;
    }

    public int minDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        return getMinDepth(root);
    }

}
